import re
import sys

# 读取.properties文件
def read_properties(file_path):
    properties = {}
    with open(file_path, 'r') as file:
        for line in file:
            line = line.strip()
            if line.startswith('#') or '=' not in line:
                continue
            key, value = line.split('=', 1)
            properties[key.strip()] = value.strip()
    return properties

# 将properties转换为yml格式
def properties_to_yml(properties):
    yml = ""
    for key, value in properties.items():
        yml += "".join(f"{key}: {value}\n")
    return yml

# 写入.yml文件
def write_yml(file_path, yml_content):
    with open(file_path, 'w') as file:
        file.write(yml_content)

# 主函数
def main(properties_file, yml_file):
    properties = read_properties(properties_file)
    yml_content = properties_to_yml(properties)
    write_yml(yml_file, yml_content)

# 程序入口
if __name__ == "__main__":
    if len(sys.argv) < 3:
        print("Usage: python convert.py input.properties output.yml")
        sys.exit(1)
    main(sys.argv[1], sys.argv[2])